﻿using AutoMapper;
using Fonour.Application.Dtos;
using Fonour.Application.Services.Interfaces;
using Fonour.Domain.Entities;
using Fonour.Domain.IRepositories;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Fonour.Application.Services
{
    /// <summary>
    /// 用户管理服务
    /// </summary>
    public class UserAppService : ServiceBase<UserDto, User>, IUserAppService
    {
        //用户管理仓储接口
        private readonly IUserRepository _userReporitory;

        private readonly IMapper _mapper;

        /// <summary>
        /// 构造函数 实现依赖注入
        /// </summary>
        /// <param name="userRepository">仓储对象</param>
        public UserAppService(IUserRepository userRepository, IMapper mapper) : base(userRepository, mapper)
        {
            _userReporitory = userRepository;
            this._mapper = mapper;
        }

        public async Task<UserDto> CheckUserAsync(string userName, string password)
        {
            var user = await _userReporitory.CheckUserAsync(userName, password);
            return this._mapper.Map<UserDto>(user);
        }

        /// <summary>
        /// 根据Id获取实体
        /// </summary>
        /// <param name="id">Id</param>
        /// <returns></returns>
        public async Task<UserDto> GetWithRolesAsync(Guid id)
        {
            var users = await this._userReporitory.GetWithRolesAsync(id);
            return this._mapper.Map<UserDto>(users);
        }
    }
}
